<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- jQuery 主文件 -->
		<script type="text/javascript" src="js/jquery.min.js" ></script>
		<!-- easyui 主文件 -->
		<script type="text/javascript" src="js/jquery.easyui.min.js" ></script>
		<!-- 国际化文件 -->
		<script type="text/javascript" src="js/locale/easyui-lang-zh_CN.js" ></script>
		<!-- easyui 主样式文件 -->
		<link rel="stylesheet" href="js/themes/default/easyui.css" />
		<link rel="stylesheet" href="js/themes/icon.css" />
<script type="text/javascript">
$(function(){ 
	$("#btnSearch").click(function () {  
        var pars = {saveDate:$('#fa').datebox('getValue')};  
        //有参数时执行此方法  
        initTable(pars);  
    });  
    //无参数时执行此方法  
    initTable("");  
})
function initTable(pars){
	$("#tb").datagrid({
	   	url:"purchaselist",
	   	method:"get",
	   	queryParams:pars,
		columns:[[  
            {field:'Id',title:'全选',width:100,checkbox:true},      
	        {field:'purchaseId',title:'订单号',width:100,align:'right'},    
	        {field:'productId',title:'产品编号',width:100,align:'right'},    
	        {field:'productName',title:'产品名称',width:100,align:'right'}, 
	        {field:'productType',title:'产品类型',width:100,align:'right'},
			{field:'productNumber',title:'产品数量',width:100,align:'right'},
			{field:'productPieces',title:'单位 ',width:100,align:'right'}, 
			{field:'productPrices',title:'单价(元)',width:100,align:'right'}, 
			{field:'purchaser',title:'采购员',width:100,align:'right'}, 
			{field:'purchasedate',title:'采购时间',width:100,align:'right'},
			{field:'dealine',title:'到货时间 ',width:100,align:'right'},
			{field:'saveDate',title:'下单时间',width:100,align:'right'},
			{field:'purchaseLister',title:'审批人',width:100,align:'right'},
			{field:'remark',title:'备注 ',width:100,align:'right'},
			{field:'supplierId',title:'供货商编号 ',width:100,align:'right'},
	    ]],
	    fit:true,
	    toolbar: '#toolbar',
		loadMsg:"亲，正在努力加载...，请耐心等候哦!!",
		pageSize:20,
		singleSelect:true,
		fitColumns:true,
		pagination:true,
		rownumbers:true,
		onClickRow:function(rowIndex, rowData){
//							alert(rowIndex);
//			alert(rowData.productName);
		}
});
}	
function print(){
	var row = $('#tb').datagrid('getSelected');	
	if (row&&row.remark=="未下单"){
		if(confirm("确定下单？")){
		location="pdf?purchaseId="+row.purchaseId;
		$('#tb').datagrid('reload');
		}
	}else{
		alert("该产品已下单");
	}
	
}
function add(){
	
	$('#win').dialog('open').dialog('setTitle','添加');
	$('#fm').form('clear');
	url = 'addPurchaseList'
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       }
function edit(){
	var row = $('#tb').datagrid('getSelected');
	if (row){
		$('#win').dialog('open').dialog('setTitle','编辑');
		$('#fm').form('load',row);	
		url = 'editPurchaseList';
	}
}
function saveUser(){
	$('#fm').form('submit',{
		url:url,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){	 
			if (result=='1'){
				$.messager.show({
					title: 'Error',
					msg: "操作失败" 
				});
			} else {
				$('#win').dialog('close');		// close the dialog
				$('#tb').datagrid('reload');	// reload the user data
			}
		}
	});
}
function select(){
	$('#won').dialog('open').dialog('setTitle','查询订单');
}

function Search(){	
	var  v = $("#ser").val();
	 $.get("SearchPurchaseList",
		   {purchaseId:v},
		   function(data1){
			$('#won').dialog('close'); 
			$('#butt').attr('disabled',"true");
			var data = eval("("+data1+")");
			$('#win').dialog('open').dialog('setTitle','订单');
			$('#fm').form('load',data);
		});
} 	
</script>
<style type="text/css">
		#fm{
			margin:0;
			padding:10px 30px;
		}
		.ftitle{
			font-size:14px;
			font-weight:bold;
			color:#666;
			padding:5px 0;
			margin-bottom:10px;
			border-bottom:1px solid #ccc;
		}
		.fitem{
			margin-bottom:5px;
		}
		.fitem label{
			display:inline-block;
			width:80px;
		}
	</style>
<title>采购列表</title>
</head>
<body> 
<table id="tb" title="订单计划表"></table>

<div id="toolbar">
	<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">添加</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="select()">查询</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-print" plain="true" onclick="print()">打印</a>
	<div style="margin-left:250px;margin-top:-26px"><input id="fa" class="easyui-datebox"><div style="margin-top:-22px;margin-left:180px"><input type="button" id="btnSearch" value="查询"></div></div> 
</div>
<div id="win" class="easyui-dialog" style="width:400px;height:400px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons">
		<div class="ftitle">PurchaseList Information</div>
		<form id="fm" method="post" novalidate>
			<div class="fitem">
				<label>purchaseId:</label>
				<input name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>productId:</label>
				<input name="productId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>productName:</label>
				<input name="productName" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>productType:</label>
				<select name="productType" class="easyui-combobox" required="true" style="width:173px;">
				   <option>组装件</option>   
                   <option>外购件</option> 
                   <option>标准件</option>   
                   <option>零件</option>
				</select>
			</div>
			<div class="fitem">
				<label>productNumber:</label>
				<input name="productNumber" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>productPieces:</label>
				<input name="productPieces" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>productPrices:</label>
				<input name="productPrices" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>purchaser:</label>
				<input name="purchaser" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>purchasedate:</label>
				<input name="purchasedate" class="easyui-datebox" required="true">
			</div>
			<div class="fitem">
				<label>dealine:</label>
				<input name="dealine" class="easyui-datebox" required="true">
			</div>
			<div class="fitem">
				<label>saveDate:</label>
				<input name="saveDate" class="easyui-datebox" required="true">
			</div>
			<div class="fitem">
				<label>purchaseLister:</label>
				<input name="purchaseLister" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>remark:</label>
				<select name="remark" class="easyui-combobox" required="true" style="width:173px;">
				   <option>未下单</option>   
                   <option>已下单</option> 
				</select>
			</div>
			<div class="fitem">
				<label>supplierId:</label>
				<input name="supplierId" class="easyui-validatebox" required="true">
			</div>
		</form>
	</div>
	<div id="won" class="easyui-dialog" style="width:400px;height:200px;padding:10px 20px"
			closed="true" buttons="#dlg-button">
			<div class="ftitle">PurchaseList Information</div>
			<form id="fm" method="post" novalidate>
			<div class="fitem">
				<label>purchaseId:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			</form>
	</div>
	<div id="dlg-button">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="Search()">Search</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#won').dialog('close')">Cancel</a>
	</div>
	<div id="dlg-buttons">
		<a href="#" id="butt" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()" >Save</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#win').dialog('close')">Cancel</a>
	</div>
</body>
</html>